package Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Dao.LearningResourceDao;
import Dao.ThumbDao;
import Entity.Thumb;

/**
 * Servlet implementation class ThumbServlet
 */
//@WebServlet("/ThumbServlet")
public class ThumbServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ThumbServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");//解决乱码
		response.setContentType("text/html;charset=utf-8");//解决乱码
		response.setCharacterEncoding("utf-8");
		PrintWriter out=response.getWriter(); //把编码设置放到输出流获取之前
		String resourceID=request.getParameter("resourceID");
		String userName=request.getParameter("userName");
		System.out.print(resourceID+""+userName);
		//int thumbNumber=new LearningResourceDao().queryLearningResourceByResourceID(resourceID).getThumbNumber();
		//List<Thumb> tlist=new ThumbDao().queryThumbByResourceID(resourceID);
		if(new ThumbDao().addThumbInformation(resourceID, userName)>0) {
			if(new LearningResourceDao().updateThumbNumberOfLearningResource(resourceID)>0) {
				//out.print("<script type='text/javascript'>alert('点赞成功！')</script>");
				response.sendRedirect("learningResource.jsp");
			}
		}
		out.flush();
		out.close();
	}

}
